﻿using System;
using log4net;

namespace Halk.Utils
{
    public class LogManage
    {
        private static LogManage _logManage;

        public static LogManage Instace()
        {
            return _logManage ?? (_logManage = new LogManage());
        }

        private readonly ILog _logger;

        private LogManage()
        {
            if (_logger == null)
                _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="log"></param>
        /// <param name="val"></param>
        public void Info(bool log, string val)
        {
            Console.WriteLine(val);
            if (log)
            {
                _logger.Info(val + "\r\n");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="log"></param>
        /// <param name="flag"></param>
        /// <param name="val"></param>
        public void Info(bool log,
                         string flag,
                         string val)
        {
            Console.WriteLine("[" + flag + "]" + val);
            if (log)
            {
                _logger.Info("[" + flag + "]" + val + "\r\n");
            }
        }

        /// <summary>
        /// Error
        /// </summary>
        /// <param name="val"></param>
        public void Error(string val)
        {
            _logger.Error(val + "\r\n");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="val"></param>
        public void Error(string flag,
                          string val)
        {
            _logger.Error("[" + flag + "]" + val + "\r\n");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="console"></param>
        /// <param name="flag"></param>
        /// <param name="val"></param>
        public void Error(bool console,
                          string flag,
                          string val)
        {
            _logger.Error("[" + flag + "]" + val + "\r\n");
            if (console)
            {
                Console.WriteLine("[" + flag + "]" + val);
            }
        }

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="console"></param>
        ///// <param name="flag"></param>
        ///// <param name="val"></param>
        //public void Error(bool console,string flag,string val)
        //{
        //    _logger.Error("[" + flag + "]" + " " + val + "\r\n");
        //    if (console)
        //    {
        //        Console.WriteLine("[" + flag + "]" + " " + val);
        //    }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="flag"></param>
        ///// <param name="config"></param>
        ///// <param name="val"></param>
        //public void Error(string flag,
        //                  ConfigEntity config,
        //                  string val)
        //{
        //    _logger.Error("[" + flag + "]" + " " + config.Flag + " " + val + "\r\n");
        //}


        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="log"></param>
        ///// <param name="config"></param>
        ///// <param name="flag"></param>
        ///// <param name="val"></param>
        //public void Info(bool log,
        //                 ConfigEntity config,
        //                 string flag,
        //                 string val)
        //{
        //    Console.WriteLine("[" + flag + "]" + " " + config.Flag + " " + val);
        //    if (log)
        //    {
        //        _logger.Info("[" + flag + "]" + " " + config.Flag + " " + val + "\r\n");
        //    }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="log"></param>
        ///// <param name="config"></param>
        ///// <param name="val"></param>
        //public void Info(bool log,
        //                 ConfigEntity config,
        //                 string val)
        //{
        //    Console.WriteLine(config.Flag + " " + val);
        //    if (log)
        //    {
        //        _logger.Info(config.Flag + " " + val + "\r\n");
        //    }
        //}
    }
}